﻿using Microsoft.Xna.Framework;

namespace Ah.Testudin.Engine.AI
{
    public class AIStateMachine
    {
        #region Private Member Variables

        private IBrain _brain;

        private IBehavior _currentBehavior;

        #endregion

        public AIStateMachine(IBrain brain)
        {
            _brain = brain;
        }

        #region Methods

        public void SetBehavior(IBehavior behavior)
        {
            if ((_currentBehavior == null) || 
                (behavior.GetType() != _currentBehavior.GetType()))
            {
                _currentBehavior = behavior;
            }
        }

        public void ChooseBestBehavior()
        {
            IBehavior behavior = _brain.Think();

            SetBehavior(behavior);
        }

        public void Update(GameTime gameTime)
        {
            if (_currentBehavior != null)
            {
                _currentBehavior.Update(gameTime);
            }
        }

        #endregion
    }
}
